#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
开放商户 - 进件取消服务
"""

from jlpay.services.base_service import BaseService
from jlpay.model.openmerch.register.incoming_cancel import IncomingCancelRequest, IncomingCancelResponse


class IncomingCancelService(BaseService):
    """进件取消服务"""
    
    def __init__(self, config):
        """
        初始化进件取消服务
        
        Args:
            config: OrgConfig实例
        """
        super().__init__(config)
    
    def get_api_url(self, request_class, api_path=None):
        """
        获取API URL
        
        Args:
            request_class: 请求类
            api_path: 接口路径
            
        Returns:
            完整的API URL
        """
        base_url = self.config.url
        
        if api_path:
            return f"{base_url}{api_path}"
        
        # 直接使用Request类中定义的完整API路径
        api_url = getattr(request_class, 'API_URL', '')
        
        if not api_url:
            # 如果没有定义API_URL，使用默认路径
            return f"{base_url}/open/merch/access/incoming/cancel"
        
        # 直接返回完整路径
        return f"{base_url}{api_url}"
    
    def cancel_incoming(self, request: IncomingCancelRequest) -> IncomingCancelResponse:
        """
        取消进件申请
        
        Args:
            request: IncomingCancelRequest实例
            
        Returns:
            IncomingCancelResponse: 进件取消响应结果
        """
        return self.post(request, IncomingCancelResponse) 